package com.xbkaoyan.libcommon.utils

import android.content.Context
import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.xuexiang.xui.utils.DrawableUtils

/**
 * Created by small-ho on 2020/11 6:22 PM
 * title: Glide工具类
 */
object GlideUtils {


    /** 默认加载方式  */
    fun loadImg(context: Context, url: Any, imageView: ImageView) {
        Glide.with(context).load(url).into(imageView)
    }

    fun loadImgWithPlace(context: Context, url: Any, imageView: ImageView) {
        var colorDrawable = DrawableUtils.getDrawable(0)
        Glide.with(context).load(url).placeholder(colorDrawable).into(imageView)
    }


    fun loadImg(context: Context, url: Any, imageView: ImageView, @DrawableRes resourceId: Int) {
        Glide.with(context).load(url).thumbnail(0.1f)
            .error(resourceId)
            .placeholder(resourceId)
            .fallback(resourceId)
            .into(imageView)
    }

    fun loadImg(fragment: Fragment, url: Any, imageView: ImageView, @DrawableRes resourceId: Int) {
        Glide.with(fragment).load(url).thumbnail(0.1f)
            .error(resourceId)
            .placeholder(resourceId)
            .fallback(resourceId)
            .into(imageView)
    }


}